package com.hankol.community.view;

import android.content.Context;
import android.text.SpannableStringBuilder;
import android.text.Spanned;
import android.text.style.ForegroundColorSpan;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.Nullable;
import androidx.core.content.ContextCompat;

import com.hankol.community.R;
import com.hankol.community.bean.FollowDynamicBean;

import java.util.List;

/**
 * @author:hanke 2022/4/6
 * desc:
 */
public class HotCommentsView extends LinearLayout {
    private View mRootView;
    private TextView commentOne;
    private TextView commentTwo;
    private TextView commentNameOne;
    private TextView commentNameTwo;
    private LinearLayout commentTwoLL;

    public HotCommentsView(Context context) {
        super(context);
        init(context);
    }

    public HotCommentsView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        init(context);
    }

    public HotCommentsView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init(context);
    }

    public HotCommentsView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
        super(context, attrs, defStyleAttr, defStyleRes);
        init(context);
    }

    private void init(Context context) {
        mRootView = LayoutInflater.from(context).inflate(R.layout.layout_hot_comments, this);
        commentOne = mRootView.findViewById(R.id.tv_comment_one);
        commentTwo = mRootView.findViewById(R.id.tv_comment_two);
        commentNameOne = mRootView.findViewById(R.id.tv_comment_name_one);
        commentNameTwo = mRootView.findViewById(R.id.tv_comment_name_two);
        commentTwoLL = mRootView.findViewById(R.id.ll_two);
    }

    public void setData(Context context, List<FollowDynamicBean.DataBeanX.BottomCommentBean> beans) {
        if (beans.size() == 1) {
            commentNameOne.setText(beans.get(0).getName() + ":");
            commentOne.setText(beans.get(0).getContent());
            commentTwoLL.setVisibility(GONE);
        } else if (beans.size() == 2) {
            commentTwoLL.setVisibility(VISIBLE);
            commentNameOne.setText(beans.get(0).getName() + ":");
            commentOne.setText(beans.get(0).getContent());
            commentNameTwo.setText(beans.get(1).getName() + ":");
            commentTwo.setText(beans.get(1).getContent());
        }
    }

}
